package cn.finyzq.ss.games.utils;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

/**
 * Create Time: 2018年05月05日 14:51
 *
 * @author fin
 */
public class FileUtils {

    /** logger */
    private static Logger logger = LogManager.getLogger(FileUtils.class);


    public static String saveFile(String fileName, String dir, String host, MultipartFile upload) {
        File file = new File(dir + fileName);
        try {
            file.mkdirs();
            file.createNewFile();
            upload.transferTo(file);
        } catch (IOException e) {
            logger.error("文件保存失败", e);

        }
        return host + fileName;

    }

    public static String getFileExtendName(String fileName){
        int i = fileName.split("\\.").length;
        return fileName.split("\\.")[i - 1];
    }


}
